import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [{
        // 默认跳转登录
        path: '/',
        name: 'index',
        component: () =>
            import ('../views/index.vue')
    },
    {
        //首页
        path: '/login',
        name: 'login',
        component: () =>
            import ('../views/login.vue')
    },
    {
        // 登录
        path: '/login',
        name: 'login',
        component: () =>
            import ('../views/login.vue')
    },
    {
        // 注册
        path: '/regist',
        name: 'regist',
        component: () =>
            import ('../views/regist.vue')
    },
    {
        // 首页
        path: '/index',
        name: 'Index',
        component: () =>
            import ( /* webpackChunkName: "index" */ '../views/index.vue')
    },
    {
        // 公司新闻
        path: '/about',
        name: 'about',
        component: () =>
            import ('../views/about.vue')
    },
    {
        // 公司新闻
        path: '/news',
        name: 'news',
        component: () =>
            import ('../views/news.vue')
    },
    {
        // 详情
        path: '/detail',
        name: 'detail',
        component: () =>
            import ('../views/detail.vue')
    },
    {
        // 咨询师
        path: '/consultant',
        name: 'consultant',
        component: () =>
            import ('../views/consultant.vue')
    },
    {
        // 咨询师详情
        path: '/consultant_list',
        name: 'consultant_list',
        component: () =>
            import ('../views/consultant_list.vue')
    },
    {
        // 
        path: '/consultantList',
        name: 'consultantList',
        component: () =>
            import ('../views/consultantList.vue')
    },
    {
        // 业务与服务
        path: '/service',
        name: 'service',
        component: () =>
            import ('../views/service.vue')
    },
    {
        // 咨询师类型选择
        path: '/counsel',
        name: 'counsel',
        component: () =>
            import ('../views/counsel.vue')
    },
    {
        // 认证协议
        path: '/deal',
        name: 'deal',
        component: () =>
            import ('../views/deal.vue')
    },
    {
        // 会员登录
        path: '/classLogin',
        name: 'classLogin',
        component: () =>
            import ('../views/classLogin.vue')
    },
    {
        // 会员注册
        path: '/classRe',
        name: 'classRe',
        component: () =>
            import ('../views/classRe.vue')
    },
    {
        // grid布局
        path: '/grid',
        name: 'grid',
        component: () =>
            import ('../views/grid.vue')
    },
]


const router = new VueRouter({

    base: process.env.BASE_URL,
    routes
})


// 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
router.beforeEach((to, from, next) => {
    if (to.path === '/login') {
        next();
    } else {
        let token = localStorage.getItem('Authorization');
        next();

    }
});
export default router